﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AbstraX.TypeMappings;
using System.Xml.Schema;
using System.Diagnostics;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            var dotNetTypes = TypeMapper.DotNetMappings.Values.Select(m => Type.GetType(m.MappedToType)).ToList<Type>();
            var xmlTypes = TypeMapper.DotNetMappings.Values.Select(m => (XmlTypeCode)Enum.Parse(typeof(XmlTypeCode), m.MappedFromType, true)).ToList<XmlTypeCode>();

            dotNetTypes = ShuffleList<Type>(dotNetTypes);
            xmlTypes = ShuffleList<XmlTypeCode>(xmlTypes);

            foreach (Type type in dotNetTypes)
            {
                XmlTypeCode typeCode = type.GetXMLType();

                Debug.WriteLine(Enum.GetName(typeof(XmlTypeCode), typeCode));
            }

            dotNetTypes = ShuffleList<Type>(dotNetTypes);

            foreach (Type type in dotNetTypes)
            {
                foreach (XmlTypeCode typeCode in xmlTypes)
                {
                    var supports = type.MapsTo(typeCode);

                    if (supports)
                    {
                        Debug.WriteLine(type.Name + " == " + Enum.GetName(typeof(XmlTypeCode), typeCode));
                    }
                    else
                    {
                        Debug.WriteLine(type.Name + " != " + Enum.GetName(typeof(XmlTypeCode), typeCode));
                    }
                }
            }
        }

        private static List<E> ShuffleList<E>(List<E> inputList)
        {
            List<E> randomList = new List<E>(); Random r = new Random();
            int randomIndex = 0;

            while (inputList.Count > 0)
            {
                randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
                randomList.Add(inputList[randomIndex]); //add it to the new, random list
                inputList.RemoveAt(randomIndex); //remove to avoid duplicates
            } 
            
            return randomList; //return the new random list
        }    
    }
}
